/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "scanner_info.h"

namespace OHOS::Scan {


//tcp 
ScanDeviceInfoTCP::ScanDeviceInfoTCP() 
{
    deviceName="";
    uuid="";
    model="";
    manufacturer="";
    deviceType="";
    port="";
    addr="";
    button="";
    feeder="";
    deviceState = 0;
}

ScanDeviceInfoTCP::ScanDeviceInfoTCP(const ScanDeviceInfoTCP &right)
{
    deviceName = right.deviceName;
    uuid = right.uuid;
    model = right.model;
    manufacturer = right.manufacturer;
    deviceType = right.deviceType;
    port = right.port;
    addr = right.addr;
    button = right.button;
    feeder = right.feeder;
    deviceState = right.deviceState;
}

ScanDeviceInfoTCP &ScanDeviceInfoTCP::operator=(const ScanDeviceInfoTCP &right)
{
    if (this != &right) {
        deviceName = right.deviceName;
        uuid = right.uuid;
        model = right.model;
        manufacturer = right.manufacturer;
        deviceType = right.deviceType;
        port = right.port;
        addr = right.addr;
        button = right.button;
        feeder = right.feeder;
        deviceState = right.deviceState;
    }
    return *this;
}

void ScanDeviceInfoTCP::SetDeviceName(const std::string& deviceName_){
    deviceName = deviceName_;
}

void ScanDeviceInfoTCP::SetUuid(const std::string& uuid_){
    uuid = uuid_;
}

void ScanDeviceInfoTCP::SetModel(const std::string& model_){
    model = model_;
}

void ScanDeviceInfoTCP::SetManufacturer(const std::string& manufacturer_){
    manufacturer = manufacturer_;
}

void ScanDeviceInfoTCP::SetDeviceType(const std::string& deviceType_){
    deviceType = deviceType_;
}

void ScanDeviceInfoTCP::SetPort(const std::string& port_){
    port = port_;
}

void ScanDeviceInfoTCP::SetAddr(const std::string& addr_){
    addr = addr_;
}

void ScanDeviceInfoTCP::SetButton(const std::string& button_){
    button = button_;
}

void ScanDeviceInfoTCP::SetFeeder(const std::string& feeder_){
    feeder = feeder_;
}

void ScanDeviceInfoTCP::SetDeviceState(const uint32_t& deviceState_){
    deviceState = deviceState_;
}

const std::string& ScanDeviceInfoTCP::GetDeviceName() const{
    return deviceName;
}

const std::string& ScanDeviceInfoTCP::GetUuid() const{
    return uuid;
}

const std::string& ScanDeviceInfoTCP::GetModel() const{
    return model;
}

const std::string& ScanDeviceInfoTCP::GetManufacturer() const{
    return manufacturer;
}

const std::string& ScanDeviceInfoTCP::GetDeviceType() const{
    return deviceType;
}

const std::string& ScanDeviceInfoTCP::GetPort() const{
    return port;
}

const std::string& ScanDeviceInfoTCP::GetAddr() const{
    return addr;
}

const std::string& ScanDeviceInfoTCP::GetButton() const{
    return button;
}

const std::string& ScanDeviceInfoTCP::GetFeeder() const{
    return feeder;
}

const uint32_t& ScanDeviceInfoTCP::GetDeviceState() const{
    return deviceState;
}

bool ScanDeviceInfoTCP::ReadFromParcel(Parcel &parcel)
{
    SetDeviceName(parcel.ReadString());
    SetUuid(parcel.ReadString());
    SetModel(parcel.ReadString());
    SetManufacturer(parcel.ReadString());
    SetDeviceType(parcel.ReadString());
    SetPort(parcel.ReadString());
    SetAddr(parcel.ReadString());
    SetButton(parcel.ReadString());
    SetFeeder(parcel.ReadString());
    return true;
}

bool ScanDeviceInfoTCP::Marshalling(Parcel &parcel) const
{
    parcel.WriteString(GetDeviceName());
    parcel.WriteString(GetUuid());
    parcel.WriteString(GetModel());
    parcel.WriteString(GetManufacturer());
    parcel.WriteString(GetDeviceType());
    parcel.WriteString(GetPort());
    parcel.WriteString(GetAddr());
    parcel.WriteString(GetButton());
    parcel.WriteString(GetFeeder());
    return true;
}

std::shared_ptr<ScanDeviceInfoTCP> ScanDeviceInfoTCP::Unmarshalling(Parcel &parcel)
{
    auto nativeObj = std::make_shared<ScanDeviceInfoTCP>();
    if (nativeObj == nullptr) {
        SCAN_HILOGE("Failed to create scaner info object");
        return nullptr;
    }
    if (!nativeObj->ReadFromParcel(parcel)) {
        SCAN_HILOGE("Failed to unmarshalling scaner info");
        return nullptr;
    }
    return nativeObj;
}

//libusb
ScanDeviceInfoLibUSB::ScanDeviceInfoLibUSB() 
{
    deviceName="";
    manufacturer="";
    model = "";
    deviceType = "";
    deviceState = 0;
}

ScanDeviceInfoLibUSB::ScanDeviceInfoLibUSB(const ScanDeviceInfoLibUSB &right)
{
    deviceName = right.deviceName;
    manufacturer = right.manufacturer;
    model = right.model;
    deviceType = right.deviceType;
    deviceState = right.deviceState;
}

ScanDeviceInfoLibUSB &ScanDeviceInfoLibUSB::operator=(const ScanDeviceInfoLibUSB &right)
{
    if (this != &right) {
        deviceName = right.deviceName;
        manufacturer = right.manufacturer;
        model = right.model;
        deviceType = right.deviceType;
        deviceState = right.deviceState;
    }
    return *this;
}


void ScanDeviceInfoLibUSB::SetDeviceName(const std::string& deviceName_){
    deviceName = deviceName_;
}

const std::string& ScanDeviceInfoLibUSB::GetDeviceName() const{
    return deviceName;
}

void ScanDeviceInfoLibUSB::SetManufacturer(const std::string& manufacturer_){
    manufacturer = manufacturer_;
}

const std::string& ScanDeviceInfoLibUSB::GetManufacturer() const{
    return manufacturer;
}

void ScanDeviceInfoLibUSB::SetModel(const std::string& model_){
    model = model_;
}

const std::string& ScanDeviceInfoLibUSB::GetModel() const{
    return model;
}

void ScanDeviceInfoLibUSB::SetDeviceType(const std::string& deviceType_){
    deviceType = deviceType_;
}

const std::string& ScanDeviceInfoLibUSB::GetDeviceType() const{
    return deviceType;
}

void ScanDeviceInfoLibUSB::SetDeviceState(const uint32_t& deviceState_){
    deviceState = deviceState_;
}

const uint32_t& ScanDeviceInfoLibUSB::GetDeviceState() const{
    return deviceState;
}

bool ScanDeviceInfoLibUSB::ReadFromParcel(Parcel &parcel)
{
    SetDeviceName(parcel.ReadString());
    SetManufacturer(parcel.ReadString());
    SetModel(parcel.ReadString());
    SetDeviceType(parcel.ReadString());
    return true;
}

bool ScanDeviceInfoLibUSB::Marshalling(Parcel &parcel) const
{
    parcel.WriteString(GetDeviceName());
    parcel.WriteString(GetManufacturer());
    parcel.WriteString(GetModel());
    parcel.WriteString(GetDeviceType());
    return true;
}

std::shared_ptr<ScanDeviceInfoLibUSB> ScanDeviceInfoLibUSB::Unmarshalling(Parcel &parcel)
{
    auto nativeObj = std::make_shared<ScanDeviceInfoLibUSB>();
    if (nativeObj == nullptr) {
        SCAN_HILOGE("Failed to create scaner info object");
        return nullptr;
    }
    if (!nativeObj->ReadFromParcel(parcel)) {
        SCAN_HILOGE("Failed to unmarshalling scaner info");
        return nullptr;
    }
    return nativeObj;
}

} // namespace OHOS::Scan